<?php

namespace App\Models;

use App\Models\Like;
use App\Models\User;
use Illuminate\Database\Eloquent\Model;

class Comment extends Model
{
    public $dateFormat = 'U';

    public function user()
    {
        return $this->hasOne(User::class,'id','user_id')->select('id','username','avatar');
    }

    /**
     * 帖子表
     */
    public function article()
    {
        return $this->belongsTo('App\Models\Article','article_id','id')->select('id','title');
    }

    /**
     * 关联点赞
     */
    public function like()
    {
        return $this->hasMany(Like::class,'comment_id','id');
    }
}
